﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Editors.Controls
{
    public partial class Remedy : DialogEditBase
    {
        public Remedy()
        {
            InitializeComponent();
            BindCombos();
        }

        public Common.Enumerations.DataTypes DataType { get; private set; }

        private void BindCombos()
        {
            if (Program.LookupTableData != null)
            {
                ComboOptions.RemedyStatus(comboBoxRemedyStatus);
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public object Data
        {
            get
            {
                return bindingSourceRemedy.DataSource;
            }
            set
            {
                bindingSourceRemedy.SuspendBinding();
                SetupDatabindings(value);
                bindingSourceRemedy.DataSource = value;
                bindingSourceRemedy.ResumeBinding();
            }
        }

        [DefaultValue(false)]
        public bool EditAllowed { get; set; }

        private void SetupDatabindings(object data)
        {
            if (data.GetType() == typeof(PolePosition.v3.EntityLibrary.UtilityAssetXMissionStructurePolesCrossRemedyVendorInspectionVisitEntity))
            {
                DataType = Common.Enumerations.DataTypes.WorkQueueXmission;
                this.bindingSourceRemedy.DataSource = typeof(PolePosition.v3.EntityLibrary.UtilityAssetXMissionStructurePolesCrossRemedyVendorInspectionVisitEntity);
            }
            else if (data.GetType() == typeof(PolePosition.v3.EntityLibrary.VendorDistributionPoleRemedyEntity))
            {
                DataType = Common.Enumerations.DataTypes.WorkQueueDistribution;
                this.bindingSourceRemedy.DataSource = typeof(PolePosition.v3.EntityLibrary.VendorDistributionPoleRemedyEntity);
            }

            this.comboBoxRemedyStatus.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bindingSourceRemedy, "RemedyStatusFK", true, DataSourceUpdateMode.OnPropertyChanged));
            this.textBoxAssignment.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSourceRemedy, "RemedyAssigned", true, DataSourceUpdateMode.OnPropertyChanged));
            this.dateTimeInputCloseDate.DataBindings.Add(new System.Windows.Forms.Binding("ValueObject", this.bindingSourceRemedy, "RemedyResolvedDate", true, DataSourceUpdateMode.OnPropertyChanged));
            this.textBoxComments.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSourceRemedy, "RemedyNotes", true, DataSourceUpdateMode.OnPropertyChanged));

        }


    }
}
